package com.tang.model.proxy.dynamicproxy.typroxy.client;

import com.tang.model.proxy.dynamicproxy.typroxy.proxy.TyClassLoader;
import com.tang.model.proxy.dynamicproxy.typroxy.proxy.TyInvocationHandler;
import com.tang.model.proxy.dynamicproxy.typroxy.proxy.TyProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Author tangyuan2meicloud.com
 * @DATE 2021/8/17 6:20
 * @Desc 红娘
 * @Remarks
 */
public class MatchmakerProxy implements TyInvocationHandler {
    private Object person;

    public  Object getInstance(Object person) {
        this.person = person;
        return TyProxy.newInstance(new TyClassLoader(), person.getClass().getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws InvocationTargetException, IllegalAccessException {
        System.out.println("现在你的需求是什么？");
        Object result = method.invoke(person, args);
        System.out.println("已经为你物色到合适的对象！开始交往！");
        return result;
    }
}
